/*
 * @Author: Royce
 * @Des: [📅日历]
 * @flow
 * @Date: 2019-03-23 15:52:42
 */

import React, {Component} from 'react';
import {
    StyleSheet,
    View,
    Image
} from 'react-native';
import Picker from 'antd-mobile-rn/lib/picker';
import List from 'antd-mobile-rn/lib/list';
export default class Pickers extends Component<Props, State> {


    constructor(props: Props) {
        super(props);

        this.countYYMM('2018-10', '2019-4');

    }

    countYYMM = (dateFrom: string, dateNow: string) => {
        let dateFromArr = dateFrom.split('-');
        let dateNowArr = dateNow.split('-');
        let dateArray = [];
        let formYear = parseInt(dateFromArr[0]);
        let formMonth = parseInt(dateFromArr[1]);
        let nowYear = parseInt(dateNowArr[0]);
        let nowMonth = parseInt(dateNowArr[1]);
        if (dateFromArr.length === 2) {
            for (let indexYear = formYear; indexYear <= nowYear; indexYear++) {
                let minMonth = (formYear < indexYear) ? 1 :formMonth;
                let maxMonth = (indexYear === nowYear) ? (nowMonth):13;
                for (let indexMonth = minMonth; indexMonth <= maxMonth; indexMonth++) {
                    const dateString = indexYear.toString() + '-' + (indexMonth<10?'0':'')+indexMonth.toString();
                    const timeObj = {
                        value: dateString,
                        label: dateString
                    };
                    dateArray.push(timeObj);
                }
            }
        }
        dateArray.push({value:'all', label:'全部账单'});
        return dateArray.reverse();


    };

    render() {

        return (

            <View style={{flex:1, width:'100%',backgroundColor: 'white'}}>
                <Picker
                    data={this.countYYMM('2018-10', '2019-4')}
                    cols={1}
                    title={'选择时间段'}
                    itemStyle={{color:'#666666', fontSize:15}}
                    onChange={this.onChange}
                >
                    <List.Item arrow="horizontal" onPress={this.onPress}>
                        省市选择
                    </List.Item>
                </Picker>
            </View>

        );
    }
    onChange = (value) =>{
        console.log(value);
    }

}

const styles = StyleSheet.create({
    calendar: {
        borderRadius: 8
    },

});